# -*- coding: utf-8 -*-

from abstract_sensor.definition import SmartAbstractSensor
from abstract_fusion_node.definition import SmartAbstractFusionNode

import quantities
import signal
import time
import sys
import random

def sig_handler(signum, frame):
    print "\nAus Maus"    
    sys.exit(1)

class MySmartAbstractFusionNode(SmartAbstractFusionNode):
    
    def __init__(self, outputDataSheet, sensor_interface, appName, outputLayer=[], logger=[]):
        SmartAbstractFusionNode.__init__(self, 
                                     outputDataSheet=outputDataSheet,
                                     inputDataSheet=inputDataSheet,
                                     appName = appName)
              
    def input_event_filtering(self):
        self.input_layer.input_events.append(self.input_layer.input_event)
        return True        
        
    def input_event_access(self):       
        self.input_events=self.input_layer.input_events
        print "Input events", self.input_events
    
    def processing_ctr(self):
        results=[]
        return results
    
    def evaluation_fct(self):
        common_validity=1
        return common_validity
    
    def output_event_mapping(self, results, common_validity):
        meas=self.input_events[0].get_value('Measurement')
        self.output_event.set_value(meas, 'Measurement')
        self.output_event.set_value(5.0*quantities.second, 'Timestamp')
        self.output_event.set_value([0.5]*quantities.centimeter**2, 'Uncertainty')
        self.output_event.set_value([100, 200, 0]*quantities.centimeter, 'Position')
        self.output_event.set_value([100, 200, 0]*quantities.degree, 'Orientation') 
        self.output_event.set_value([common_validity], 'Validity')        


if __name__ == "__main__":

    output_channel_file='../datasheets/events/'+"Dist_IRe.xml"
    input_channel_files=['../datasheets/events/'+"Dist_IRe.xml"]
                         
    SAFN = MySmartAbstractFusionNode(outputDataSheet=output_channel_file,
                                 inputDataSheets=input_channel_file,
                                 appName="SAS Test",
                                 logger=[])
    print SAFN       
    SAFN.startMeasurements()
    
    print "Mit STRG + C beenden."
    signal.signal(signal.SIGINT, sig_handler)    
    
    while 1:
        time.sleep(1)
